package com.tianhui.consignortwofei.other.auth.recognition.recognitionResultProcess;

import com.baidu.ocr.sdk.model.IDCardResult;
import com.fgs.common.utils.DateUtil;
import com.fgs.common.utils.LogUtil;
import com.tianhui.consignortwofei.mvp.model.enty.authLicense.IdCardInfo;
import com.xuexiang.xutil.net.JsonUtil;

/**
 * @author fgs
 * @date 2020/11/16
 * @description
 **/
public class IdCardOcrResultProcess {
    public IdCardInfo getIdCardOcrResult(IDCardResult idCardResult) {
        IdCardInfo idCardInfo = new IdCardInfo();

        if (idCardResult == null) {
            return idCardInfo;
        }

        if (idCardResult.getName() != null) {

            idCardInfo.name = (idCardResult.getName().getWords());
            LogUtil.print("姓名：", idCardInfo.name);
        }
        if (idCardResult.getIdNumber() != null) {

            idCardInfo.idNumber = (idCardResult.getIdNumber().getWords());
            LogUtil.print("身份证：", idCardInfo.idNumber);
        }
        if (idCardResult.getAddress() != null) {

            idCardInfo.address = (idCardResult.getAddress().getWords());
        }
        if (idCardResult.getExpiryDate() != null) {
            String endTime = idCardResult.getExpiryDate().getWords();
            idCardInfo.idcardendtime = dateFormat(endTime);
            LogUtil.print("身份证失效日期", idCardResult.getExpiryDate().getWords());
        }
        LogUtil.print("idCardInfo", JsonUtil.toJson(idCardInfo));
        return idCardInfo;
    }

    public String dateFormat(String date) {
        return DateUtil.validDateFormat(date, "yyyyMMdd");
    }
}
